﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// 对材质颜色 进行呼吸效果过渡
/// </summary>
[RequireComponent(typeof(MeshRenderer))]
// [AddComponentMenu("Material/SineColor")]
public class MaterialSineColor : SineBase
{

    public Color targetColor = Color.red;
    public Color currentColor = Color.white;

    private MeshRenderer meshRenderer;

    private void Awake()
    {
        this.AfterInit();
        meshRenderer = GetComponent<MeshRenderer>();
        currentColor = meshRenderer.material.color;
    }

    protected override void AfterInit()
    {
        this.GetComponent<SpriteRenderer>();

        this.magnitude = 1.0f;
        this.initialValue = this.magnitude / 2;
        this.periodOffset = -this.period / 2;
        this.lastKnownValue = this.initialValue;
    }


    protected override void UpdateFromPhase(float value)
    {
        this.meshRenderer.material.color = Color.Lerp(this.currentColor, this.targetColor, (value + 1) / 2);
    }
}
